<link rel="stylesheet" href="__PUBLIC__/statics/default/assets/css/email.css">

<div id="email">
    <div class="content">
		<div class="title"><?php echo getLangByKey($language,"E-mail Form"); ?></div>
        <div class="sub-title"><?php echo getLangByKey($language,"Note! Fields marked with * are mandatory and must be fill in!"); ?></div>
        <div class="form">
            <form id="user_form" action="{:U('Others/Others_addok')}">
                <input type="text" name="company" value="" placeholder="<?php echo getLangByKey($language,"Company name"); ?>：*"><br>
                <input type="text" name="title" value="" placeholder="<?php echo getLangByKey($language,"Name"); ?>：*"><br>
                <input type="text" name="country" value="" placeholder="<?php echo getLangByKey($language,"Country"); ?>：*"><br>
                <input type="text" name="tell" value="" placeholder="<?php echo getLangByKey($language,"Contact number"); ?>：*"><br>
                <input type="text" name="mail" value="" placeholder="<?php echo getLangByKey($language,"Your e-mail address"); ?>：*"><br>
                <div class="select-area" style="padding:0;height:44px">
                    <input type="hidden" name="" value="">
                    <?php $pro_cat = get_category('2'); //AAA($l1); ?>
					<select style="width: 100%;height:44px" name="product_cat" id="" product_cat="" >
						<option value="">--<?php echo getLangByKey($language,"Please select"); ?>--</option>
						<?php foreach($pro_cat as $one_cat){ ?>
						<option value="{$one_cat['category_id']}"><?php echo getLangByKey($language,$one_cat['cat_name']); ?></option>
						<?php } ?>
					</select>
					<input type="hidden" value="" name="product_category" style="background;red" />
                </div>
                <ul>
					<?php foreach($pro_cat as $one_cat){
						$pro_list = cat2article($one_cat['category_id'],$is_all=1,$num=10,$order='no');
							foreach($pro_list['lists'] as $one_pro){
					?>
                    <li class="" style="display:none"     pro_id="{$one_pro['product_id']}" pro_name="{$one_pro['title']}" pro_cat="{$one_cat['category_id']}" ><?php echo $one_pro['title']; ?></li>
					<?php }} ?>

					<input type="hidden" value="" name="product_name" style="background;red" />
                </ul>
				<input type="hidden" name="liuyan" value="1" />
                <textarea name="description" rows="4" cols="80" placeholder="<?php echo getLangByKey($language,"Message"); ?>：*"></textarea><br>
                <div class="btn-area">
                    <button id="subbtn" type="submit" name="button"><?php echo getLangByKey($language,"Send"); ?><i></i></button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
$(function() {
	var pro_cat = {
		<?php foreach($pro_cat as $key=>$one_cat){

		echo '"'.$one_cat['category_id'].'":"'.$one_cat['cat_name'].'"';
			if($key!=count($pro_cat)-1){
				echo ',';
			}
		}?>
	};
    $('#email ul li').on('click', function() {

        var html = '';
        if ($(this).hasClass('active')) {
            $(this).removeClass('active');
        } else {
            $(this).addClass('active');
        }

		var pro_name=[];
		var selected = $('.active');
		for(var i=0;i<selected.length;i++){
			//alert( String(selected.eq(i).attr('pro_name')));
			pro_name[i] = String( selected.eq(i).attr('pro_name'))
		}
		//console.log(pro_name)
		$("input[name='product_name']").val(pro_name.join(','))

    });
	$('#email select').change(function(){
		if($(this).val()!=''){
			var pro_cat_id = $(this).val();
			//alert($(this).val());
			$('#email ul li').removeClass('active').hide();
			$('#email ul li[pro_cat='+pro_cat_id+']').show();

			$("input[name='product_category']").val(pro_cat[pro_cat_id])

		}
	})
	$('#subbtn').click(function(e){
		e.preventDefault();

		var errorStr='';

		$("input[name='company']").removeClass('error');
		if($("input[name='company']").val()==''){
			errorStr+='请填写公司名称';
			$("input[name='company']").addClass('error')
		}

		$("input[name='title']").removeClass('error');
		if($("input[name='title']").val()==''){
			errorStr+='</br>请填写姓名';
			$("input[name='title']").addClass('error')
		}

		$("input[name='country']").removeClass('error');
		if($("input[name='country']").val()==''){
			errorStr+='</br>请填写所在国家';
			$("input[name='country']").addClass('error')
		}

		$("input[name='tell']").removeClass('error');
		if($("input[name='tell']").val()==''){
			errorStr+='</br>请填写联系电话';
			$("input[name='tell']").addClass('error')
		}

		$("input[name='mail']").removeClass('error');
		if($("input[name='mail']").val()==''){
			errorStr+='</br>请填写邮件';
			$("input[name='mail']").addClass('error')
		}

		$("select[name='product_cat']").removeClass('error');
		if($("select[name='product_cat']").val()==''){
			errorStr+='</br>请选择产品类型';
			$("select[name='product_cat']").addClass('error')


		}


		$("textarea[name='description']").removeClass('error');
		if($("textarea[name='description']").val()==''){
			errorStr+='</br>请填写需求描述';
			$("textarea[name='description']").addClass('error')
		}

		if(errorStr!=''){
			Message(errorStr);
		}else{
			$('#user_form').submit();
		}


	})
});
</script>
